﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BLL
{
    using EXT;
    using System.Data;
    public class NhanvienBLL:DAL.NhanvienDAL
    {
        public bool IsExists(string Ma)
        {
            var dt = base.Nhanvien_Select_By_Ma(Ma);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    return true;
                }
            }
            return false;
        }

        public bool IsExistsShowTrue(Guid Id_Nhomnguoidung)
        {
            var dt = base.Nhanvien_Select_By_Id_Nhomnguoidung(Id_Nhomnguoidung);
            int x = dt.Rows.Count;
            if (x>0)
            {
                for (int i = 0; i < x; i++)
                {
                    if (dt.Rows[i]["Show"].ToBoolean())
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public string CheckLogin(string Ma, string Pass)
        {
            DataTable ND = new DataTable();
            if (Ma.Trim() == "") return "=0";
            try
            {
                ND = base.Nhanvien_Select_By_Ma(Ma);
            }
            catch (Exception)
            {
                return "=00";
            }
            if (ND.Rows.Count == 0) return "=1";
            if (Pass.MaHoaMD5() != ND.Rows[0]["Pass"].ToString()) return "=2";
            return String.Format("{0}={1}={2}={3}", ND.Rows[0]["Id"], ND.Rows[0]["Ma"], ND.Rows[0]["Ten"], ND.Rows[0]["Id_Nhomnguoidung"].GetGuid());
        }
    }
}
